# -*- coding: utf-8 -*-

from extension import db
# from sqlalchemy import Date
from sqlalchemy import ForeignKey


class Job(db.Model):
    __tablename__ = 'job'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    job_people = db.Column(db.String(255), nullable=False)
    job_content = db.Column(db.String(255), nullable=False)
    job_last_date = db.Column(db.String(255), nullable=False)
    job_important = db.Column(db.Integer, nullable=False)
    job_delay = db.Column(db.Integer, nullable=False)
    job_delay_reason = db.Column(db.String(255), nullable=False)

    @staticmethod
    def init_db():
        rets = [
            (1, '张三', '剪枝', '2024/6/25', 1, 0, ''),
            (2, '李四', '浇水', '2024/6/30', 1, 1, '没水')
        ]
        for ret in rets:
            job = Job()
            job.id = ret[0]
            job.job_people = ret[1]
            job.job_content = ret[2]
            job.job_last_date = ret[3]
            job.job_important = ret[4]
            job.job_delay = ret[5]
            job.job_delay_reason = ret[6]
            db.session.add(job)
        db.session.commit()


# 只设置任务内容、负责人、截止日期，不可延期
class UrgentJob(db.Model):
    __tablename__ = 'urgent_task'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    job_people = db.Column(db.String(255), nullable=False)
    job_content = db.Column(db.String(255), nullable=False)
    job_last_date = db.Column(db.String(255), nullable=False)

    @staticmethod
    def init_db():
        rets = [
            (1, '养护人员1', '紧急任务1', '2024/6/25'),
            (2, '养护人员2', '紧急任务2', '2024/6/30')
        ]
        for ret in rets:
            job = UrgentJob()
            job.id = ret[0]
            job.job_people = ret[1]
            job.job_content = ret[2]
            job.job_last_date = ret[3]
            db.session.add(job)
        db.session.commit()


class Role(db.Model):
    __tablename__ = 'role'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    role_name = db.Column(db.String(255), nullable=False)

    @staticmethod
    def init_db():
        rets = [
            (1, '超级管理员'),
            (2, '校级管理员'),
            (3, '养护人员')
        ]
        for ret in rets:
            role = Role()
            role.id = ret[0]
            role.role_name = ret[1]
            db.session.add(role)
        db.session.commit()

class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_name = db.Column(db.String(255), nullable=False)
    user_password = db.Column(db.String(255), nullable=False)
    # role_id = db.Column(db.Integer, nullable=False)

    @staticmethod
    def init_db():
        rets = [
            (1, 'admin', '123456'),
            (2, 'school-admin', '123456'),
            (3, 'maintenance-personnel', '123456')
        ]
        for ret in rets:
            user = User()
            user.id = ret[0]
            user.user_name = ret[1]
            user.user_password = ret[2]
            db.session.add(user)
        db.session.commit()

class Role_User(db.Model):
    __tablename__ = 'role_user'
    role_id = db.Column(db.Integer, ForeignKey('role.id'), primary_key=True)
    user_id = db.Column(db.Integer, ForeignKey('user.id'), primary_key=True)

    @staticmethod
    def init_db():
        rets = [
            (1, 1),
            (2, 2),
            (3, 3)
        ]
        for ret in rets:
            role_user = Role_User()
            role_user.role_id = ret[0],
            role_user.user_id = ret[1]
            db.session.add(role_user)
        db.session.commit()

class Permission(db.Model):
    __tablename__ = 'pemission'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    description = db.Column(db.String(255), nullable=False)

    @staticmethod
    def init_db():
        rets = [
            (1, 'permission1'),
            (2, 'permission2'),
            (3, 'permission3')
        ]
        for ret in rets:
            permission = Permission()
            permission.id = ret[0]
            permission.description = ret[1]
            db.session.add(permission)
        db.session.commit()


